home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
taropyon
/
splib
/
splib.lzh
/
PRG
/
LHX
/
DOSIO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-08
|
2KB
|
85 lines
/***********************************************************
dosio.c -- MS-DOS dependent I/O
***********************************************************/
#include "lh386.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <dos.h>
#include "lh.h"
#ifdef __HIGHC__
# pragma On(Align_labels);
#endif
time_t getfiletime(FILE * f)
{
union stamp stamp;
#ifdef __HIGHC__
unsigned int dt, tm;
_dos_getftime(fileno(f), &dt, &tm);
stamp.t.date = dt;
stamp.t.time = tm;
#else
_dos_getftime(fileno(f), (unsigned short *) &(stamp.t.date),
(unsigned short *) &(stamp.t.time));
#endif
return dos2unix(&stamp.s);
}
int setfiletime(FILE * f, time_t utc)
{
union stamp *stamp;
stamp = (union stamp *) unix2dos(utc);
fflush(f);
return _dos_setftime(fileno(f), stamp->t.date, stamp->t.time);
}
static char physicaldrive(char *filename)
{
#if 0
union REGS regs;
char physical[80];
strcpy(physical, filename);
regs.x.si = (unsigned) filename;
regs.x.di = (unsigned) physical;
regs.h.ah = 0x60;
intdos(®s, ®s);
fprintf(stderr, " = '%c'\n", *physical);
return *physical - 'A' + 1;
#else
if (filename[1] == ':')
{
return toupper(filename[0]) - 'A' + 1;
} else
{
unsigned drv;
_dos_getdrive(&drv);
return ((char) drv);
}
#endif
}
long diskspace(char *filename)
{
struct diskfree_t dtable;
struct find_t srchbuf;
long cluster, freespace;
if (_dos_findfirst(filename, 0x07, &srchbuf))
srchbuf.size = 0;
_dos_getdiskfree(physicaldrive(filename), &dtable);
cluster = (long) dtable.bytes_per_sector * (long) dtable.sectors_per_cluster;
freespace = (long) dtable.avail_clusters * cluster;
freespace += (srchbuf.size + cluster - 1) / cluster * cluster;
return freespace;
}